package com.imooc.router.asm

import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ScopedArtifacts
import org.gradle.api.Plugin
import org.gradle.api.Project


/**
 *@author: xiaosy
 *时间: 2024/11/12
 *@Description: java类作用描述
 *@Version: 1.0
 **/
class ASMRouterPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        println("ASMRouterPlugin start >>>")

        val androidComponentsExtension =
            project.extensions.getByType(AndroidComponentsExtension::class.java)

        androidComponentsExtension.onVariants { variant ->
//            val args = variant.javaCompilation.annotationProcessor.arguments
//            args.put("root_project_dir", project.rootProject.projectDir.absolutePath)
//            println("ASMRouterPlugin args >>>$args")
            val task = project.tasks.register("${variant.name}RouterTask", RouterTask::class.java)
            variant.artifacts.forScope(ScopedArtifacts.Scope.ALL)
                .use(task)
                .toTransform(
                ScopedArtifact.CLASSES,
                RouterTask::allJars,
                RouterTask::allDirectories,
                RouterTask::output
            )
        }
    }
}